﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MovieRecorder.CUiMRCRecorderIndicator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace DnProcessSimulateCommands.MovieRecorder;

public class CUiMRCRecorderIndicator : Window, IComponentConnector
{
  private CApMRCRecorderIndicatorViewModel m_viewModel;
  internal Polyline m_topLeft;
  internal Polyline m_bottomLeft;
  internal Polyline m_topRight;
  internal Polyline m_bottomRight;
  private bool _contentLoaded;

  public CUiMRCRecorderIndicator(Point topLeftInPixels, Point bottomRightInPixels)
  {
    this.InitializeComponent();
    this.m_viewModel = new CApMRCRecorderIndicatorViewModel(topLeftInPixels, bottomRightInPixels);
    this.DataContext = (object) this.m_viewModel;
    this.Left = SystemParameters.VirtualScreenLeft;
    this.Top = SystemParameters.VirtualScreenTop;
    this.Width = SystemParameters.VirtualScreenWidth;
    this.Height = SystemParameters.VirtualScreenHeight;
    this.m_bottomLeft.SetValue(RenderOptions.EdgeModeProperty, (object) EdgeMode.Aliased);
    this.m_bottomRight.SetValue(RenderOptions.EdgeModeProperty, (object) EdgeMode.Aliased);
    this.m_topLeft.SetValue(RenderOptions.EdgeModeProperty, (object) EdgeMode.Aliased);
    this.m_topRight.SetValue(RenderOptions.EdgeModeProperty, (object) EdgeMode.Aliased);
  }

  private void Window_Loaded(object sender, RoutedEventArgs e)
  {
    HwndSource.FromHwnd(new WindowInteropHelper((Window) this).Handle).AddHook(new HwndSourceHook(this.WndProc));
    this.UpdateRecordingBorders(this.m_viewModel.TopLeft, this.m_viewModel.BottomRight);
  }

  private void Window_Closed(object sender, EventArgs e) => this.BlinkingFrames.Stop();

  internal void UpdateRecordingBorders(Point topLeftInPixels, Point bottomRightInPixels)
  {
    this.BlinkingFrames.Stop();
    this.m_viewModel.TopLeft = this.PointFromScreen(topLeftInPixels);
    this.m_viewModel.BottomRight = this.PointFromScreen(bottomRightInPixels);
    Point bottomRight;
    if (this.Width < this.m_viewModel.BottomRight.X)
    {
      bottomRight = this.m_viewModel.BottomRight;
      this.Width = bottomRight.X;
    }
    double height = this.Height;
    bottomRight = this.m_viewModel.BottomRight;
    double y = bottomRight.Y;
    if (height < y)
    {
      bottomRight = this.m_viewModel.BottomRight;
      this.Height = bottomRight.Y;
    }
    this.m_viewModel.UpdateData();
    if (this.m_viewModel.ApplyOffset)
      return;
    this.BlinkingFrames.Begin();
  }

  internal void ApplyOffset()
  {
    this.BlinkingFrames.Stop();
    this.m_viewModel.ApplyOffset = true;
  }

  internal void RemoveOffset()
  {
    this.m_viewModel.ApplyOffset = false;
    this.BlinkingFrames.Begin();
  }

  private Storyboard BlinkingFrames => this.FindResource((object) "BlinkFrame") as Storyboard;

  private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  {
    if (msg != 33)
      return IntPtr.Zero;
    handled = true;
    return new IntPtr(3);
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/movierecorder/recordingindication/cuimrcrecorderindicator.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((FrameworkElement) target).Loaded += new RoutedEventHandler(this.Window_Loaded);
        ((Window) target).Closed += new EventHandler(this.Window_Closed);
        break;
      case 2:
        this.m_topLeft = (Polyline) target;
        break;
      case 3:
        this.m_bottomLeft = (Polyline) target;
        break;
      case 4:
        this.m_topRight = (Polyline) target;
        break;
      case 5:
        this.m_bottomRight = (Polyline) target;
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
